package WebTopN6;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class WebBean implements WritableComparable<WebBean> {
    private String province;
    private String year;
    private float web;

    public WebBean(){
    }

    public WebBean(String province, String year, float web){
        this.province = province;
        this.year = year;
        this.web = web;
    }
    public void set(String province, String year, float web) {
        this.province = province;
        this.year = year;
        this.web = web;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public float getWeb() {
        return web;
    }

    public void setWeb(float web) {
        this.web = web;
    }

    @Override
    public String toString() {
        return" " +
                "省份=" + province +
                ",年份=" + year +
                ",内地居民结婚登记数=" + web;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(province);
        dataOutput.writeUTF(year);
        dataOutput.writeFloat(web);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.province = dataInput.readUTF();
        this.year = dataInput.readUTF();
        this.web = dataInput.readFloat();
    }

    @Override
    public int compareTo(WebBean o) {

        int result ;

        int i = year.compareTo(o.getYear());

        if ( i > 0) {
            result =1;
        } else if (i <0 ) {
            result = -1;
        } else {
            // 内地居民结婚登记数倒序排序
            result = this.web > o.getWeb() ? -1 : (this.web < o.getWeb()? 1:0);
        }
        return result;
    }


}
